<template>
  <el-container class="home-container">
    <!-- 头部 -->
    <el-header>
      <div>
        <img src="../../assets/img/logo.png" alt="网页图" />
        <template>
          <div>
            <span @click="backhome">首页</span>
            <el-divider direction="vertical"></el-divider>
            <span>{{ this.$store.state.userdata.userName }}</span>
          </div>
        </template>
      </div>
    </el-header>
    <!-- 页面主体 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <el-menu
          :default-active="activePath"
          :router="true"
          :collapse-transition="false"
          :collapse="isCollapse"
          unique-opened
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409eff"
        >
          <el-submenu
            :index="item.id + ''"
            v-for="item in menulist"
            :key="item.id"
          >
            <!-- 一级菜单模板区 -->
            <template slot="title">
              <i :class="iconsObj[item.id]"></i>
              <span>{{ item.authName }}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item
              :index="'/' + subItem.path"
              v-for="subItem in item.children"
              :key="subItem.id"
              @click="saveNavState('/' + subItem.path)"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ subItem.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      menulist: [
        {
          id: 1,
          authName: "个人中心",
          children: [
            {
              id: 1,
              authName: "修改密码",
              path: "ppassword",
            },
            {
              id: 2,
              authName: "个人信息",
              path: "puser",
            },
            {
              id: 3,
              authName: "简历信息",
              path: "resume",
            },
          ],
        },
        {
          id: 2,
          authName: "简历信息管理",
          children: [
            {
              id: 1,
              authName: "已投简历列表",
              path: "pbusiness",
            },
          ],
        },
      ],
      iconsObj: {
        1: "el-icon-user-solid",
        2: "el-icon-s-tools",
      },
      isCollapse: false,
      // 被激活的链接地址
      activePath: "",
    };
  },
  methods: {
    // 点击按钮切换菜单的折叠与展开
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    //保存链接的激活状态
    saveNavState(activePath) {
      window.sessionStorage.setItem("activePath", activePath);
      this.activePath = activePath;
    },
    //跳回主页
    backhome() {
      this.$router.push("/");
    },
  },
};
</script>

<style lang="less" scoped>
.el-button {
  height: 40px;
  margin-top: 10px;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  //   align-content: center;
  color: #fff;
  font-size: 20px;
  line-height: 60px;
  > div {
    width: 100%;
    // display: flex;
    align-items: center;
    margin-left: 20px;
    img {
      margin-top: 13px;
      float: left;
    }
    > div {
      float: right;
      span {
        margin-left: 15px;
      }
    }
  }
}
.el-aside {
  background-color: #333744;
  height: 693px;
  .el-menu {
    border-right: none;
    .el-submenu {
      padding-left: 0px !important;
      .el-menu-item {
        padding-left: 70px !important;
      }
    }
  }
}
.el-main {
  background-color: #eaedf1;
}
.home-container {
  height: 100%;
}
.iconfont {
  margin-right: 10px;
}
.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2rem;
  cursor: pointer;
}
</style>